home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 2
/
SPACE - Library 2 - Volume 1.iso
/
music
/
55
/
applic
/
enhance.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-09-18
|
17KB
|
785 lines
#include <osbind.h>
#include <stdio.h>
#include <butmac.h>
WORD handle,work_in[12],mouse;
/* handle - GEM AES graphics handle
work_in - GEM VDI input array
mouse - flag indicates graphic cursor state (ON or OFF) */
WORD work_out[57],c_ht,c_wd,rcv_flag;
/* work_out - GEM VDI output array
c_ht - character height in pixels
c_wd - character width " "
rcv_flag - indicates ASCII recording ON or OFF */
WORD palette[16],rgb_in[3],xr,yr,xc,yc,margin,res,inv_video;
BYTE *gbuf, *scrn;
FILE *s_chan;
/* gbuf - graphics buffer pointer
scrn - screen buffer array */
WORD pxy[8];
struct mfdb{
LONG address;
WORD width, height, raster, form, planes, dummy1, dummy2, dummy3;
}sMFDB,dMFDB;
WORD intin[128], intout[128], ptsin[128], ptsout[128], contrl[12];
main()
{
int iii;
iii = 0;
init();
while(iii != -1){
control();
}
}
/* ----------------- program termination ------------------- */
end_prg()
{
Mfree(scrn); /* return array space */
Cconout(ESC); /* cursor off */
Cconout('f');
v_clrwk(handle); /* clear screen */
v_clsvwk(handle); /* tell AES we're quitting */
appl_exit(); /* and terminate */
Pterm0();
}
init()
{
/* usual GEM VDI & AES initializers */
WORD i,j,x,h,p; /* local variables */
LONG crud;
appl_init(); /* initialize application */
handle = graf_handle(&x,&x,&x,&x); /* get VDI graphics handle */
for(i=0;i<10;i++)work_in[i]=1; /* set up workstation */
work_in[10]=2; /* " " " */
v_opnvwk(work_in,&handle,work_out); /* " " " */
graf_mouse(256,0); /* mouse off */
v_clrwk(handle); /* clear screen */
xr = work_out[0];
yr = work_out[1];
vq_extnd(handle,1,work_out);
crud = Malloc(32000L); /* space for screen */
if(crud <= 0L){
printf("ERROR - insuficient memory!");Cconin();
Pterm0();
}
dMFDB.address = crud;
sMFDB.address = Physbase();
sMFDB.height = 399; /* yr; */
sMFDB.width = 639; /* xr; */
sMFDB.raster = 40; /* xr / 16; */
sMFDB.form = 1;
sMFDB.planes = 1; /* work_out[4]; */
sMFDB.dummy1 = 0;
sMFDB.dummy2 = 0;
sMFDB.dummy3 = 0;
dMFDB.height = 399; /* yr; */
dMFDB.width = 639; /* xr; */
dMFDB.raster = 40; /* xr / 16; */
dMFDB.form = 1;
dMFDB.planes = 1; /* work_out[4]; */
dMFDB.dummy1 = 0;
dMFDB.dummy2 = 0;
dMFDB.dummy3 = 0;
pxy[0] = 0;
pxy[1] = 0;
pxy[2] = 639;
pxy[3] = 399;
pxy[4] = 0;
pxy[5] = 0;
pxy[6] = 639;
pxy[7] = 399;
graf_mouse(0,0L);
graf_mouse(257,0L);
i = form_alert(1,"[0][Welcome to ENHANCE|<HELP> gives a function menu][Okay]");
graf_mouse(256,0L);
Cconout(BELL);
v_clrwk(handle);
}
/* -------------- DEGAS screen load (needs work) -------------- */
load_pic() /* starts like send_file() */
{
BYTE d_path[256],f_spec[256],f_name[40];
WORD j, r, ret, button, p_chan;
BYTE c,*pbuf;
unsigned WORD i,n;
strcpy(d_path,"\\*.*");
strcpy(f_spec,"________.___");
sav_scrn();
graf_mouse(0,0L);
graf_mouse(257,0L);
ret = fsel_input(d_path,f_spec,&button);
graf_mouse(256,0L);
rst_scrn();
if(button == 1){
r = Getrez();
combine(d_path,f_spec,f_name);
for(i=0;i<40;i++){
if((f_name[i] == '.')||(f_name[i] == 0))break;
}
f_name[i++] = '.';
f_name[i++] = 'p'; /* here the file .ext is forced */
f_name[i++] = 'i';
c = r + 49;
f_name[i++] = c;
f_name[i] = 0;
p_chan = Fopen(f_name,1);
if(p_chan > 0){
pbuf = (BYTE *)&r;
n = Fread(p_chan,2L,pbuf); /* mark the resolution */
for(i=0;i<16;i++){ /* and the color palette */
n = Fread(p_chan,2L,pbuf);
}
pbuf = (BYTE *)dMFDB.address;
n = Fread(p_chan,32000L,pbuf);
if(n != 32000)printf("error - sav_pic failed!\n");
Fclose(p_chan); /* and close the file */
rst_scrn();
Cconout(BELL); /* *** DING *** */
}
else{
button = form_alert(1,"[1][That file cannot be opened.][O.K.]");
}
}
}
/* -------------- DEGAS screen save (needs work) -------------- */
sav_pic() /* starts like send_file() */
{
BYTE d_path[256],f_spec[256],f_name[40];
WORD j, r, ret, button, p_chan;
BYTE c,*pbuf;
unsigned WORD i,n;
strcpy(d_path,"\\*.*");
strcpy(f_spec,"________.___");
sav_scrn();
graf_mouse(0,0L);
graf_mouse(257,0L);
ret = fsel_input(d_path,f_spec,&button);
graf_mouse(256,0L);
rst_scrn();
if(button == 1){
r = Getrez();
combine(d_path,f_spec,f_name);
for(i=0;i<40;i++){
if((f_name[i] == '.')||(f_name[i] == 0))break;
}
f_name[i++] = '.';
f_name[i++] = 'p'; /* here the file .ext is forced */
f_name[i++] = 'i';
c = r + 49;
f_name[i++] = c;
f_name[i] = 0;
p_chan = Fcreate(f_name,0);
if(p_chan > 0){
pbuf = (BYTE *)&r;
n = Fwrite(p_chan,2L,pbuf); /* mark the resolution */
for(i=0;i<16;i++){ /* and the color palette */
j = Setcolor(i,-1);
pbuf = (BYTE *)&j;
n = Fwrite(p_chan,2L,pbuf);
}
pbuf = (BYTE *)dMFDB.address;
n = Fwrite(p_chan,32000L,pbuf);
if(n != 32000)printf("error - sav_pic failed!\n");
Fclose(p_chan); /* and close the file */
Cconout(BELL); /* *** DING *** */
}
else{
button = form_alert(1,"[1][That file cannot be opened.][O.K.]");
}
}
}
/* ------ utility to generate file spec. from fsel_input() data ------ */
combine(d_s,f_s,f_n)
BYTE *d_s,*f_s,*f_n;
/* Local Vars: */
/* d_s : disk specification (A:\\)
f_s : file specification (test.dat)
f_n : file name (A:\\test.dat) */
{
BYTE q;
while((q = *d_s++) != '*')*f_n++ = q; /* copy from d_s */
while((q = *f_s++) != 0)*f_n++ = q; /* then copy f_s */
*f_n = 0; /* and terminate the string */
}
/* ------------------- utility to save screen in char. array ------------ */
sav_scrn()
{
vro_cpyfm(handle,3,pxy,&sMFDB,&dMFDB);
}
/* ------------ restore a previously saved screen ------------------ */
rst_scrn()
{
vro_cpyfm(handle,3,pxy,&dMFDB,&sMFDB);
}
/*---------------- message() - string printing -------------- */
message(s)
char *s;
{
char q;
while ((q = *s++) != 0)Cconout(q);
}
gcharc()
{
LONG q;
WORD i,j;
q = Crawcin(); /* get scan code */
i = q & 65535; /* we only want low 16 bits */
if(i != 0)return(i); /* bank 1 - return it */
q = q - i; /* it's bank 2: convert */
j = q / 65536;
j = j + 128; /* bump it up to 128 - 255 */
return(j); /* and return it */
}
control()
{
int i;
i = gcharc();
if(i == HELP){ /* user wants the help menu */
sav_scrn(); /* save screen */
Cconout(ESC); /* clear screen & home cursor */
Cconout('E');
printf("The following Functions are Implemented:\n\n");/* display menu */
printf("F1 - load picture\n");
printf("F2 - save picture\n");
printf("F3 - enhance (SLOW)\n");
printf("F4 - eliminate grey\n");
printf("F5 - invert\n");
printf("F6 - edge (SLOW - run F3 first)\n");
printf("F7 - dither\n");
printf("F8 - scramble\n");
printf("F9 - save to TEK file (SLOW! MEMORY HOG!\n");
printf("F10 - print screen\n");
printf("CLR - clear screen\n");
printf("UNDO - quit\n");
printf("\nhit any key:");
Cconin();
rst_scrn(); /* restore screen */
}
else if(i == F2){ /* user wants to save screen (DEGAS) */
sav_pic(); /* execute */
}
else if(i == F1){
load_pic();
}
else if(i == F3)enhance();
else if(i == F4)grid();
else if(i == F5)invert();
else if(i == F6)edge();
else if(i == F7)dither();
else if(i == F8)scramble();
else if(i == F9)tek();
else if(i == F10)print_screen(sMFDB.address);
else if(i == CLR){
v_clrwk(handle);
sav_scrn();
}
else if(i == UNDO){
end_prg();
}
}
scramble()
{
WORD x0,y0,i,x1,y1;
LONG j;
register WORD x,y,xx,yy;
sav_scrn();
v_clrwk(handle);
for(x = 1;x < 640;x = x + 2){
for(y = 1;y < 400;y = y + 2){
x0 = x - 1;
y0 = y - 1;
x1 = x + 1;
y1 = y + 1;
i = 0;
for(xx = x0;xx < x1;xx++){
for(yy = y0;yy < y1;yy++){
i = i + point(dMFDB.address,xx,yy);
}
}
if(i == 1){
if((j = Random()) < 9500000L)set(sMFDB.address,x0,y0,1);
if((j = Random()) < 9500000L)set(sMFDB.address,x0,y,1);
if((j = Random()) < 9500000L)set(sMFDB.address,x,y,1);
if((j = Random()) < 9500000L)set(sMFDB.address,x,y0,1);
}
else if(i == 2){
if((j = Random()) < 11500000L)set(sMFDB.address,x0,y0,1);
if((j = Random()) < 11500000L)set(sMFDB.address,x0,y,1);
if((j = Random()) < 11500000L)set(sMFDB.address,x,y,1);
if((j = Random()) < 11500000L)set(sMFDB.address,x,y0,1);
}
else if(i == 3){
if((j = Random()) < 15000000L)set(sMFDB.address,x0,y0,1);
if((j = Random()) < 15000000L)set(sMFDB.address,x0,y,1);
if((j = Random()) < 15000000L)set(sMFDB.address,x,y,1);
if((j = Random()) < 15000000L)set(sMFDB.address,x,y0,1);
}
else if(i == 4){
set(sMFDB.address,x0,y0,1);
set(sMFDB.address,x0,y,1);
set(sMFDB.address,x,y,1);
set(sMFDB.address,x,y0,1);
}
}
}
sav_scrn();
}
dither()
{
WORD x0,y0,i,x1,y1;
register WORD x,y,xx,yy;
sav_scrn();
v_clrwk(handle);
for(x = 1;x < 640;x = x + 2){
for(y = 1;y < 400;y = y + 2){
x0 = x - 1;
y0 = y - 1;
x1 = x + 1;
y1 = y + 1;
i = 0;
for(xx = x0;xx < x1;xx++){
for(yy = y0;yy < y1;yy++){
i = i + point(dMFDB.address,xx,yy);
}
}
if(i == 1){
set(sMFDB.address,x0,y0,1);
set(sMFDB.address,x0,y,0);
set(sMFDB.address,x,y,0);
set(sMFDB.address,x,y0,0);
}
else if(i == 2){
set(sMFDB.address,x0,y0,0);
set(sMFDB.address,x0,y,1);
set(sMFDB.address,x,y,0);
set(sMFDB.address,x,y0,1);
}
else if(i == 3){
set(sMFDB.address,x0,y0,0);
set(sMFDB.address,x0,y,1);
set(sMFDB.address,x,y,1);
set(sMFDB.address,x,y0,1);
}
else if(i == 4){
set(sMFDB.address,x0,y0,1);
set(sMFDB.address,x0,y,1);
set(sMFDB.address,x,y,1);
set(sMFDB.address,x,y0,1);
}
}
}
sav_scrn();
}
invert()
{
register WORD i,x,y;
sav_scrn();
for(x = 1;x < 639; x++){
for(y = 1;y < 399; y++){
i = point(sMFDB.address,x,y);
if(i != 0)set(sMFDB.address,x,y,0);
else set(sMFDB.address,x,y,1);
}
}
}
edge()
{
register WORD x,y,i;
WORD x0,x1,y0,y1;
sav_scrn();
/* clear edge */
for(x = 0;x < 640;x++){
set(sMFDB.address,x,0,0);
set(sMFDB.address,x,399,0);
}
for(y = 0;y < 400;y++){
set(sMFDB.address,0,y,0);
set(sMFDB.address,639,y,0);
}
/* now do it */
for(x = 1;x < 639; x++){
for(y = 1;y < 399; y++){
i = 0;
x0 = x - 1;
x1 = x + 1;
y0 = y - 1;
y1 = y + 1;
i = i + point(dMFDB.address,x0,y0);
i = i + point(dMFDB.address,x0,y);
i = i + point(dMFDB.address,x0,y1);
i = i + point(dMFDB.address,x,y0);
i = i + point(dMFDB.address,x,y);
i = i + point(dMFDB.address,x,y1);
i = i + point(dMFDB.address,x1,y0);
i = i + point(dMFDB.address,x1,y);
i = i + point(dMFDB.address,x1,y1);
if((i == 0)||(i == 9))set(sMFDB.address,x,y,0);
else set(sMFDB.address,x,y,1);
}
}
}
enhance()
{
register WORD x,y,i;
WORD x0,x1,y0,y1;
sav_scrn();
/* clear edge */
for(x = 0;x < 640;x++){
set(sMFDB.address,x,0,0);
set(sMFDB.address,x,399,0);
}
for(y = 0;y < 400;y++){
set(sMFDB.address,0,y,0);
set(sMFDB.address,639,y,0);
}
/* now do it */
for(x = 1;x < 639; x++){
for(y = 1;y < 399; y++){
i = 0;
x0 = x - 1;
x1 = x + 1;
y0 = y - 1;
y1 = y + 1;
i = i + point(dMFDB.address,x0,y0);
i = i + point(dMFDB.address,x0,y);
i = i + point(dMFDB.address,x0,y1);
i = i + point(dMFDB.address,x,y0);
i = i + point(dMFDB.address,x,y);
i = i + point(dMFDB.address,x,y1);
i = i + point(dMFDB.address,x1,y0);
i = i + point(dMFDB.address,x1,y);
i = i + point(dMFDB.address,x1,y1);
if(i > 4)set(sMFDB.address,x,y,1);
else set(sMFDB.address,x,y,0);
}
}
}
grid()
{
register WORD x,y,i,j;
WORD x0,x1,y0,y1;
sav_scrn();
/* clear edge */
for(x = 0;x < 640;x++){
set(sMFDB.address,x,0,0);
set(sMFDB.address,x,399,0);
}
for(y = 0;y < 400;y++){
set(sMFDB.address,0,y,0);
set(sMFDB.address,639,y,0);
}
/* now do it */
for(x = 1;x < 639; x++){
for(y = 1;y < 399; y++){
i = 0;
x0 = x - 1;
x1 = x + 1;
y0 = y - 1;
y1 = y + 1;
i = i + point(dMFDB.address,x0,y0);
i = i + point(dMFDB.address,x0,y);
i = i + point(dMFDB.address,x0,y1);
i = i + point(dMFDB.address,x,y0);
i = i + point(dMFDB.address,x,y1);
i = i + point(dMFDB.address,x1,y0);
i = i + point(dMFDB.address,x1,y);
i = i + point(dMFDB.address,x1,y1);
if(i == 4)set(sMFDB.address,x,y,0);
}
}
}
WORD point(Address,x,y)
BYTE *Address;
WORD x,y;
{
register LONG a;
register WORD b,xx;
BYTE c,d,e,power_two();
BYTE *data;
a = (LONG)y * 80L;
b = x / 8;
a = a + (LONG)b + (LONG)Address;
data = (BYTE *)a;
d = *data;
xx = b * 8;
xx = x - xx;
xx = 7 - xx;
c = power_two(xx);
d = c & d;
if(d == 0)return(0);
else return(1);
}
set(Address,x,y,val)
BYTE *Address;
WORD x,y,val;
{
register LONG a;
register WORD b,xx;
BYTE c,d,e,power_two();
BYTE *data;
a = (LONG)y * 80L;
b = x / 8;
a = a + (LONG)b + (LONG)Address;
data = (BYTE *)a;
d = *data;
xx = b * 8;
xx = x - xx;
xx = 7 - xx;
c = power_two(xx);
d = c & d;
d = 255 - d;
*data = *data & d;
if(val != 0)*data = *data | c;
}
BYTE power_two(x)
register WORD x;
{
if(x == 0)return(1);
else if(x == 1)return(2);
else if(x == 2)return(4);
else if(x == 3)return(8);
else if(x == 4)return(16);
else if(x == 5)return(32);
else if(x == 6)return(64);
else if(x == 7)return(128);
else return(0);
}
send_file()
{
BYTE d_path[256],f_spec[256],f_name[40];
WORD ret, button;
/* local vars: */
/* d_path - pathname (i.e. - disk & directory)
f_spec - file specification
f_name - file name
ret - return value
button - button value */
sav_scrn();
strcpy(d_path,"\\*.*"); /* set up arrays */
strcpy(f_spec,"________.___");
graf_mouse(0,0L);
graf_mouse(257,0L);
ret = fsel_input(d_path,f_spec,&button); /* get user's selection */
graf_mouse(256,0L);
if(button == 1){ /* user selected a file: */
combine(d_path,f_spec,f_name); /* get the filename */
s_chan = fopen(f_name,"bw"); /* open it */
}
rst_scrn();
}
tek() /* sends screen to file */
{
WORD xl,yl,xh,yh,xm,ym,oyh,oyl,oxh,yflag,a,b,width,height;
register LONG xx,yy;
register WORD i,j;
LONG x00,y00,x11,y11;
send_file();
graf_mouse(0,0L);
graf_mouse(257,0L);
i = form_alert(1,"[0][Position mouse at upper left|corner of digitizing region|then hold down button|and drag to lower right corner][okay...]");
graf_mouse(5,0L);
i = evnt_button(1,1,1,&xm,&ym,&a,&b);
graf_mouse(0,0L);
i = graf_rubberbox(xm,ym,1,1,&width,&height);
graf_mouse(256,0L);
rst_scrn();
x00 = (LONG)xm * 1023L / 639L;
y00 = 399L - (LONG)ym;
y00 = y00 * 779L / 399L;
x11 = (LONG)(xm + width);
x11 = x11 * 1023L / 639L;
y11 = (LONG)(ym + height);
y11 = 399L - y11;
y11 = y11 * 779L / 399L;
i = putc(ESC,s_chan);
i = putc(FF,s_chan);
i = putc(FS,s_chan);
for(yy = y11;yy < y00; yy = yy + 1L){
ym = (WORD)(yy * 399L / 779L);
ym = 399 - ym;
yl = yy & 31;
yh = (yy - yl) / 32;
yl = yl | 96;
yh = yh | 32;
yflag = 1;
for(xx = x00;xx < x11;xx = xx + 1L){
xm = (WORD)(xx * 639L / 1023L);
j = point(dMFDB.address,xm,ym);
if(j > 0){
xl = xx & 31;
xh = (xx - xl) / 32;
xl = xl | 64;
xh = xh | 32;
if(yflag == 1){
i = putc(yh,s_chan);
i = putc(yl,s_chan);
i = putc(xh,s_chan);
i = putc(xl,s_chan);
yflag = 0;
}
else if(oxh != xh){
i = putc(yl,s_chan);
i = putc(xh,s_chan);
i = putc(xl,s_chan);
}
else i = putc(xl,s_chan);
oxh = xh;
}
}
}
i = putc(CR,s_chan);
i = putc(BELL,s_chan);
fclose(s_chan);
Cconout(BELL);
}
print_screen(gbuf)
BYTE *gbuf;
{
WORD i,r,c;
for(i=0;i<5;i++)Cprnout(10);
Cprnout(27);
Cprnout(65);
Cprnout(8);
for(r=0;r<80;r++){
for(i=0;i<11;i++)Cprnout(32);
Cprnout(27);
Cprnout(42);
Cprnout(5);
Cprnout(144);
Cprnout(1);
for(c=399;c>-1;c--){
i = (c * 80) + r;
Cprnout(gbuf[i]);
}
Cprnout(13);
Cprnout(10);
}
Cprnout(12);
Cprnout(27);
Cprnout(64);
}